package threadProblem;

public class ThreadTest01 {
    public static void main(String[] args) {
        Thread t1 = new Thread();
        t1.start();

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName());
            }
        }, "t2");
        t2.start();

        Thread t3 = new Thread("t3");
        System.out.println(t3.getState());
        t3.start();
        System.out.println(t3.getName());
        System.out.println(t3.getId());
        System.out.println(t3.getPriority());
        System.out.println(t3.getState());
        System.out.println(t3.isAlive());
        System.out.println(t3.isDaemon());
        System.out.println(t3.isInterrupted());

        Thread thread = new Thread(()->{
            for(int i = 1; i <= 10; i++){
                try {
                    System.out.println(Thread.currentThread().getName() + "：我还活着");
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println(Thread.currentThread().getName() + "：我即将死去");
        }, "我的线程");

        thread.setDaemon(true);

        System.out.println(Thread.currentThread().getName() + "：ID：" + thread.getId());
        System.out.println(Thread.currentThread().getName() + "：名称：" + thread.getName());
        System.out.println(Thread.currentThread().getName() + "：状态：" + thread.getState());
        System.out.println(Thread.currentThread().getName() + "：优先级：" + thread.getPriority());
        System.out.println(Thread.currentThread().getName() + "：后台进程：" + thread.isDaemon());
        System.out.println(Thread.currentThread().getName() + "：活着：" + thread.isAlive());
        System.out.println(Thread.currentThread().getName() + "：被中断：" + thread.isInterrupted());

        thread.start();

        System.out.println(Thread.currentThread().getName() + "：状态：" + thread.getState());

        while(thread.isAlive()){};
        System.out.println(Thread.currentThread().getName() + "：状态：" + thread.getState());

    }
}
